/*
 * First class started by the index.html
 */

define(["dojo", "dojo/on", "dojo/topic", "app/nav/GpxReader", "app/nav/GpxParser", "dojo/domReady!"], function(dojo, on, topic, gpxReader, gpxParser) {
	dojoConfig.locale = 'nl';

	topic.subscribe("GPX_RETRIEVED", function(data) {
		drawRoute(data);
		drawLocation();
	});
	
	var map, centre;

	function initialize() 
	{
		var myOptions = {
			center : centre,
			zoom : 12,
			mapTypeId : google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(dojo.byId("map_canvas"), myOptions);
	};

	function drawRoute(data) 
	{
		console.log("drawing gpx " + data);
		coords = gpxParser.parse(data);
		centre = gpxParser.getCentre();

		var route = new google.maps.Polyline({
			path : coords,
			strokeColor : "#FF0000",
			strokeOpacity : 1.0,
			strokeWeight : 2
		});

		initialize();
		route.setMap(map);

		document.getElementById('hdr').innerHTML = 'done';
	};

	function drawLocation() 
	{
		var locationOpts = {
			strokeColor : "#00FF00",
			strokeOpacity : 0.8,
			strokeWeight : 2,
			fillColor : "#00FF00",
			fillOpacity : 0.35,
			map : map,
			center : centre,
			radius : 200
		};
		cityCircle = new google.maps.Circle(locationOpts);
		
	}


	gpxReader.getGpx();

});
